# from api.ihrmLogin import IhrmloginApi
import logging

import jsonschema

from api.ihrmLogin import IhrmloginApi  # 导包接口
from common.assertTools import common_assret #导包断言
import  logging

class TestIhrmLoginApi(object):
    def setup_class(self):
        self.ihrm_login = IhrmloginApi()


    def test01_login_success(self):
        req_data = {"mobile": "13800000002", "password": "123456"}
        res = self.ihrm_login.login(req_data)
        logging.info(f"这是晚自习作业题的日志信息:{res.json()}") #日志打印在文件的应用
        assert 200 == res.status_code
        # assert True == res.json().get("success")
        # assert 10000 == res.json().get("code")
        # assert "操作成功" in res.json().get("message")

    def test02_pass_err(self):
        # 密码错误
        req_data = {"mobile": "13800000002", "password": "12345"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        assert 200 == res.status_code
        # schema={"type":"object",
        #         "prpperties":{
        #             "success":{"const":False},
        #             "code":{"const":20001},
        #             "messagr":{"pattern":"错误"},
        #              "data":"null"},
        # #         "required":["success","code","messagr","data"]}
        # instance=res.json()
        # jsonschema.validate(instance=instance,schema=schema)
        #


        assert False == res.json().get("success")
        assert 20001 == res.json().get("code")
        assert "错误" in res.json().get("message")

    def test03_mobile_err(self):
        # 手机号未注册
        req_data = {"mobile": "1879765435", "password": "123456"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        assert 200 == res.status_code
        assert False == res.json().get("success")
        assert 20001 == res.json().get("code")
        assert "错误" in res.json().get("message")

    def test04_mobile10_err(self):
        # 手机号10位
        req_data = {"mobile": "138000000", "password": "123456"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test05_mobile12_err(self):
        # 手机号12位
        req_data = {"mobile": "138000000002", "password": "123456"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test06_mobileno_err(self):
        # 手机号空
        req_data = {"mobile": None, "password": "123456"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test07_mobilechare_err(self):
        # 手机号特殊字符
        req_data = {"mobile": "132&*7812#$", "password": "123456"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test08_pwd1_err(self):
        # 1位密码
        req_data = {"mobile": "13800000002", "password": "1"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")


    def test09_pwd100_err(self):
        # 100位密码
        req_data = {"mobile": "13800000002", "password": "123456789012345678901234567890123456789012345678901234567890"
                                                         "1234567890123456789012345678901234567890"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test10_pwdno_err(self):
        # 空密码
        req_data = {"mobile": "13800000002", "password":None}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test11_pwdchare_err(self):
        # 密码字符
        req_data = {"mobile": "13800000002", "password":"12#%$*&()"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")

    def test12_paramsmany_err(self):
        # 多参
        req_data = {"mobile": "13800000002", "password":"123456","id":"123"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,True,10000, "成功")

    def test13_params_err(self):
        # 少参
        req_data = {"mobile": "13800000002"}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")


    def test14_params_err(self):
        # 无参
        req_data = None
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,99999, "系统繁忙")


    def test15_params_err(self):
        # 多参
        req_data = {"mobile": "13800000002", "pwd":"123456",}
        res = self.ihrm_login.login(req_data)
        print(res.json())
        common_assret(res,200,False,20001, "错误")









